home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / library / mfssrgrp.lha / usergroup / initgroups.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  3KB  |  100 lines

  1. RCS_ID_C="$Id: initgroups.c,v 1.3 1994/01/21 12:34:52 ppessi Exp $";
  2. /*
  3.  * initgroups.c - group initialization function
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * This file is part of the AmiTCP/IP usergroup.library
  8.  *
  9.  * Copyright © 1993 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
  10.  *                  Helsinki University of Technology, Finland.
  11.  *
  12.  * Created      : Sun Nov 28 17:45:55 1993 ppessi
  13.  * Last modified: Fri Jan 21 11:00:41 1994 ppessi
  14.  *
  15.  * $Log: initgroups.c,v $
  16.  * Revision 1.3  1994/01/21  12:34:52  ppessi
  17.  * Fixed NI_MEMBERS interface
  18.  *
  19.  * Revision 1.2  1994/01/21  08:13:47  ppessi
  20.  * Updated documentation
  21.  *
  22.  * Revision 1.1  1994/01/19  10:04:56  ppessi
  23.  * Initial revision
  24.  *
  25.  */
  26.  
  27. /****** usergroup.library/initgroups ***************************************
  28.  
  29.     NAME
  30.         initgroups - initialize group access list
  31.  
  32.     SYNOPSIS
  33.         error = initgroups(name, basegid)
  34.          D0                 A0     D0
  35.  
  36.         int initgroups(const char *, gid_t);
  37.  
  38.     FUNCTION
  39.         The initgroups() function reads through the group file and sets up,
  40.         the group access list for the user specified in name. The basegid is
  41.         automatically included in the groups list.  Typically this value is
  42.         given as the group number from the password file.
  43.  
  44.      RESULT
  45.         The initgroups() function returns -1 if the process has got no
  46.         necessary privileges, zero if the call is succesful.
  47.  
  48.      FILES
  49.          AmiTCP:db/group
  50.  
  51.      SEE ALSO
  52.          setgroups()
  53.  
  54.      HISTORY
  55.          The initgroups function appeared in 4.2BSD.
  56.  
  57. ****************************************************************************
  58. */
  59.  
  60. #include "base.h"
  61. #include "libfunc.h"
  62.  
  63. SAVEDS ASM int R_initgroups(REG(a1) const char *name, REG(d0) gid_t basegroup)
  64. {
  65.   struct NetInfoReq *nreq;
  66.   short error = -1;
  67.  
  68.   ObtainSemaphore(ni_lock);
  69.   if (nreq = OpenNIUnit(NETINFO_GROUP_UNIT)) {
  70.     gid_t *groups = nreq->io_Data;
  71.     short ngroups, i, j;
  72.  
  73.     groups[0] = basegroup;
  74.     nreq->io_Data = groups + 1;
  75.     nreq->io_Offset = (LONG) name;
  76.     nreq->io_Command = NI_MEMBERS;
  77.  
  78.     if (myDoIO(nreq) == 0 || nreq->io_Error == NIERR_TOOSMALL) {
  79.       ngroups = nreq->io_Actual / sizeof(gid_t) + 1;
  80.       /* search for duplicate of basegroup */
  81.       for (i = j = 1; i < ngroups; i++) {
  82.     if (groups[i] != basegroup)
  83.       groups[j++] = groups[i];
  84.       }
  85.       if (j > NGROUPS)
  86.     j = NGROUPS;
  87.       error = R_setgroups(j, groups);
  88.     } else {
  89.       SetErrno((nreq->io_Error < 0) ? ENOENT : nreq->io_Error);
  90.     }
  91.   } else {
  92.     SetErrno(ENOENT);
  93.   }
  94.  
  95.   ReleaseSemaphore(ni_lock);
  96.  
  97.   return error;
  98. }
  99.  
  100.